--
-- Author: ping.wang
-- Date: 2018-09-11 20:28:04
-- 幻化
local Clothes = class("Clothes")
local string_isContain = string.isContain
local string_split = string.split

-- string id = 1;  //随从ID
-- 	int32 quality = 2;//随从品质
-- 	int32 exp = 3;    //随从经验
-- 	int32 state = 4;  //随从状态(0-未雇佣 1-雇佣

function Clothes:read(value)
	self.tid = value.tid
	self.duration = value.duration or 0
	self.conf = GD:getClothesConfig( self.tid )
	self.confRes = GD:getFashionConf( self.tid )
	assert(self.conf ~= nil, "fashion.conf can't be nil" .. self.tid)
	assert(self.confRes ~= nil, "fashion.confRes can't be nil" .. self.tid)
	self.quality = value.quality or tonumber(self.conf.quality)
	self._shareData = nil
end

function Clothes:ctor()
	self.itemBagType = Enums.ItemBagType.fashion
	self.showType = Enums.ItemShowType.fashion
	self.tid = 0
	self.quality = 1
	self._shareData = nil

	self.isNew = false
end

function Clothes:setIsNewGet(b)
	self.isNew = b
end

function Clothes:getName()
	return L(self.conf.name)
end

function Clothes:setShareData(shareData)
    self._shareData = shareData
end
function Clothes:getShareData()
    return self._shareData
end

function Clothes:getDuration()
	return self.duration
end

function Clothes:getLocation()
	return tonumber(self.conf.location or 1)
end


-- 获取类型名字
function Clothes:getTypeName()
	if self.conf.typeDesc then
		return L(self.conf.typeDesc)
	end
	return L(Res.showTypeName .. self.showType)
end

--品质框
function Clothes:getIconBg()
    return Res.Qulity_Icon_Bg[self.quality]
end

--这里比较奇葩 因为tips可以点击的icon是方形的 所以这里的图特殊处理
function Clothes:getIcon()
	if not self._icon then
       self._icon = string.format("%s%s.png", Res.weaponResPath, self.confRes.icon)
    end
    return self._icon
end

-- 临时给tips统一处理用，应该统一用上面的getResource就可以了
function Clothes:getResource()
    return self.conf.resource
end

function Clothes:getQuality()
	return self.quality or 1
end

function Clothes:getDesc()
	return L(self.conf.desc)
end
function Clothes:getClass()
	return self.conf.class or "0"
end

-- 是适合职业的道具/装备，"0"适合所有职业，默认是自己的职业
function Clothes:isClassEnable(classId)
	if classId then
		local classStr = self:getClass()
		return classStr == "0" or string_isContain(classStr, classId)
	else
		-- 自己职业的适合判定缓存起来
		if self._isClassEnable == nil then
			local classStr = self:getClass()
			classId = UD:getClass()
			self._isClassEnable = classStr == "0" or string_isContain(classStr, classId)
		end
		return self._isClassEnable
	end
end

-- 检测是否是适合职业的外显装备, classId 不填默认是自己的
-- return 是否可以，预览参数
function Clothes:isClassAvatarEnable(classId)
	local able = self:isClassEnable(classId)
	return able, able and {type=Enums.AvatarPreviewType.equip, id=self.tid} or nil
end

return Clothes